package com.music.checkpoints.common.core.security;


import org.springframework.web.filter.GenericFilterBean;

import javax.servlet.FilterChain;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.http.HttpServletRequest;
import java.io.IOException;

public class AccessTokenAuthenicationFilter extends GenericFilterBean {
    private AccessTokenAuthenticationService accessTokenAuthenticationService;

    public AccessTokenAuthenicationFilter(AccessTokenAuthenticationService accessTokenAuthenticationService) {
        this.accessTokenAuthenticationService = accessTokenAuthenticationService;
    }

    @Override
    public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain) throws IOException, ServletException {
        HttpServletRequest req = (HttpServletRequest) servletRequest;
        accessTokenAuthenticationService.auth(req);
        filterChain.doFilter(servletRequest, servletResponse);
    }
}
